package com.ship.dispatch.mapper.orderPay;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ship.dispatch.bean.ConShipping;
import com.ship.dispatch.bean.orderPay.SpFundManage;
import com.ship.dispatch.bean.orderPay.SpFundPayManageDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SpFundManageMapper  extends BaseMapper<SpFundManage> {
    /**
     * 根据航次号、公司名称、贸易模式查询预付款资金管理表信息
     */
//    @Select("select f.* from sp_fund_manage f LEFT JOIN sp_fund_manage_detail d on f.id = d.fund_manage_id\n" +
//            "where f.order_type in(1,3) and f.voyage_no = #{voyageNo} and d.corporate_name= #{corporateName} and d.trade_body = #{tradeBody} ORDER BY f.create_date desc LIMIT 1")
//    SpFundManage getFundManageAdvance(@Param("voyageNo") String voyageNo,@Param("corporateName") String corporateName,@Param("tradeBody") Integer tradeBody);

    @Select("select f.* from sp_fund_manage f LEFT JOIN sp_fund_manage_detail d on f.id = d.fund_manage_id\n" +
            "where d.corporate_name= #{corporateName} ORDER BY f.create_date desc LIMIT 1")
    SpFundManage getFundManageAdvance(@Param("voyageNo") String voyageNo,@Param("corporateName") String corporateName,@Param("tradeBody") Integer tradeBody);

    /**
     * 根据航次号、公司名称、贸易模式查询预付款资金管理表信息
     */
    @Select("select f.* from sp_fund_manage f LEFT JOIN sp_fund_manage_detail d on f.id = d.fund_manage_id\n" +
            "where f.order_type in(1,2,3,4) and f.voyage_no = #{voyageNo} and d.corporate_name= #{corporateName} and d.trade_body = #{tradeBody} ORDER BY f.create_date desc LIMIT 1")
    SpFundManage getFundManageAdvanceAndEnd(@Param("voyageNo") String voyageNo,@Param("corporateName") String corporateName,@Param("tradeBody") Integer tradeBody);

    /**
     * 根据航次号、公司名称、贸易模式查询尾款资金管理表信息
     */
    @Select("select f.* from sp_fund_manage f LEFT JOIN sp_fund_manage_detail d on f.id = d.fund_manage_id\n" +
            "where f.order_type in(2,4) and f.voyage_no = #{voyageNo} and d.corporate_name= #{corporateName} and d.trade_body = #{tradeBody} ORDER BY f.create_date desc LIMIT 1")
    SpFundManage getFundManageEnd(@Param("voyageNo") String voyageNo,@Param("corporateName") String corporateName,@Param("tradeBody") Integer tradeBody);

    /**
     * 根据航次号、公司名称、贸易模式查询预付款资金管理表信息
     */
    @Select("select f.* from sp_fund_manage f LEFT JOIN sp_fund_manage_detail d on f.id = d.fund_manage_id\n" +
            "where f.order_type in(1,3) and f.voyage_no = #{voyageNo} and d.corporate_name= #{corporateName} and d.trade_body = #{tradeBody} and f.voyage_number = #{voyageNumber} ORDER BY f.create_date desc LIMIT 1")
    SpFundManage getFundManageByVoyageNumber(@Param("voyageNo") String voyageNo,@Param("corporateName") String corporateName,@Param("tradeBody") Integer tradeBody,@Param("voyageNumber") Integer voyageNumber);

    List<SpFundManage> queryFundManageByCorporateName(@Param("corporateName") String corporateName,@Param("tradeBody") Integer tradeBody);


//    @Select("select * from sp_fund_pay_manage_detail sfpmd\n" +
//            "where sfpmd.corporate_name= #{corporateName} and sfpmd.trade_body = #{tradeBody} ORDER BY sfpmd.id desc LIMIT 1")
//    SpFundPayManageDetail getFundManageAdvanceAndEndNew(@Param("corporateName") String corporateName, @Param("tradeBody") Integer tradeBody);
    @Select("select * from sp_fund_pay_manage_detail sfpmd\n" +
            "where sfpmd.corporate_name= #{corporateName} ORDER BY sfpmd.id desc LIMIT 1")
    SpFundPayManageDetail getFundManageAdvanceAndEndNew(@Param("corporateName") String corporateName, @Param("tradeBody") Integer tradeBody);
}
